/**
 * @param {number[]} nums
 * @return {number[]}
 */
var findErrorNums = function (nums) {
    let n = nums.length;
    let dup = -1;
    for (let i = 0; i < n; i++) {
        // 现在的元素是从1开始的
        let index = Math.abs(nums[i]) - 1;
        if (nums[index] < 0) {
            dup = Math.abs(nums[i]);
        } else {
            nums[index] *= -1;
        }
    }

    let missing = -1;
    for (let i = 0; i < n; i++) {
        if (nums[i] > 0) {
            // 将索引转换成元素
            missing = i + 1;
        }
    }

    return [dup, missing]
};